// 获取接口调用凭据
// https://api.weixin.qq.com/cgi-bin/token

export const getToken = async () => {
  return new Promise((resolve, reject) => {
    uni.request({
      url: "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx0d650365fb06d99c&secret=a432c4b56f57365a523e1f950e826d35",
      method: "GET",
      success: (res) => {
        uni.showToast({
          title: JSON.stringify(res),
          icon: "none",
        });
        resolve(res.data.access_token);
      },
      fail: (err) => {
        uni.showToast({
          title: JSON.stringify(err),
          icon: "none",
        });
        reject(err);
      },
    });
  });
};

// 获取手机号
export const getPhone = (token, code) => {
  return new Promise((resolve, reject) => {
    uni.request({
      url:
        "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" +
        token,
      method: "POST",
      data: {
        code: code,
      },
      success: (res) => {
        uni.showToast({
          title: JSON.stringify(res),
          icon: "none",
        });
        resolve(res.data);
      },
      fail: (err) => {
        uni.showToast({
          title: JSON.stringify(err),
          icon: "none",
        });
        reject(err);
      },
    });
  });
};
